<%--
  Created by IntelliJ IDEA.
  User: Eternity
  Date: 2020/9/9
  Time: 19:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <style>
        .page-link{
            float: right;
            align-content: center;
            width:80px;
            height:40px;
        }
    </style>
    <script>

        $(function () {
            $("#skill").hide();
            $("#r1").click(function () {
                $("#skill").hide();
            })
            $("#r2").click(function () {
                $("#skill").show();
            })
        })

        function subpaper() {
            //获取表单信息
            var paperName = $("[name=paperName]").val()
            var paperType=$('input[name="paperType"]:checked').val();//获取选中的单选的值
            var testDate = $("[name=testDate]").val()
            var paperNumber = $("[name=paperNumber]").val()
            var cotScore = $("[name=cotScore]").val()


            if (paperName == ""){
                alert("标题不能为空！")
                return false;
            }
            if (testDate == "" && paperType == 1){
                alert("请设置考试时长！")
                return false;
            }
            if (paperNumber == "" && paperType == 1){
                alert("请设置考题数量！")
                return false;
            }
            if (cotScore == "" && paperType == 1){
                alert("请设置总分！")
                return false;
            }

            $.ajax({
                //请求路径
                url : "/paper/addPaper",
                //请求参数
                data:{
                    paperName : paperName,
                    paperType : paperType,
                    testDate : testDate,
                    paperNumber : paperNumber,
                    cotScore : cotScore
                },
                type:"post",
                dataType:"json",
                success:function (data) {
                    window.location.href="/paper/getPaperAll";
                },error:function () {
                    alert("系统异常！请稍后重试。")
                }
            })
        }


        //上线下线
        function linePar(pid) {

            $.ajax({
                //请求路径
                url : "/paper/linePaper",
                //请求参数
                data:{
                    paperId : pid
                },
                type:"post",
                dataType:"json",
                success:function (data) {
                    alert(data.msg)
                    window.location.href="/paper/pages";
                },error:function () {
                    alert("系统异常！请稍后重试。")
                }
            })

        }


    </script>
</head>
<body>
<%--头部信息--%>
<jsp:include page="hade.jsp"/>
<div class="container">
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">设置新的考题</button>
    <form action="/paper/pages" method="post">
        <div class="row">

            <div class="col-lg-7">
            </div>

            <div class="col-lg-3">
                <input type="text" class="form-control" name="name" id="selName" style="width: 270px" placeholder="请输入要查询的考卷" >
            </div>
            <div class="col-lg-2">
                <button type="submit" class="btn btn-primary">查询</button>
            </div>

        </div>
    </form>
    <table class="table table-hover">
        <thead>
        <tr>
            <th>试卷名称</th>
            <th>类型</th>
            <th>状态</th>
            <%--<th>状态2</th>--%>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${lists}" var="paper">
            <tr>
                <td>${paper.paperName}</td>
                <td>
                    <span class="badge badge-success">${paper.paperType eq 0?"普通练习题":""}</span>
                    <span class="badge badge-danger">${paper.paperType eq 1?"考试题":""}</span>
                </td>
                <td>
                    <span class="badge badge-danger">${paper.deleteFlag eq 0?"待确认":""}</span>
                    <span class="badge badge-success">${paper.deleteFlag eq 1?"已上线":""}</span>
                    <span class="badge badge-danger">${paper.deleteFlag eq 2?"已下线":""}</span>
                </td>
                <%--<td>--%>
                    <%--<span c lass="badge badge-danger">${paper.deleteFlag eq 2?"已删除":""}</span>--%>
                <%--</td>--%>
                <td>
                        <%--<a href="/account/findAccountById?id=${account.id}"><button type="button" class="btn btn-primary">编辑</button></a>--%>
                    <a href="/paper/getTopic?paperId=${paper.paperId}&pName=${paper.paperName}"><button type="button" class="btn btn-info">查看</button></a>
                    <button type="button" class="btn btn-danger" onclick="linePar(${paper.paperId})">${paper.deleteFlag eq 1?"下线":"上线"}</button>
                    <%--<a href="/paper/deletePaper?paperId=${paper.paperId}"><button type="button" class="btn btn-danger">删除</button></a>--%>

                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

<%--分页--%>
<div style="text-align: center;">
    <c:if test="${pages.total>0}">
        <span class="page-link" style="width:160px;color: dimgrey">当前第${pages.pageNum}页/共${pages.pages}页</span>
    </c:if>
    <c:if test="${pages.total>1}">
        <c:choose>
            <c:when test="${pages.pageNum==1}">
               <a href="/paper/pages?pageNum=${pages.nextPage}" class="page-link">下一页</a>
               <a href="/paper/pages?pageNum=${pages.pages}" class="page-link">末页</a>
            </c:when>
            <c:when test="${pages.pageNum==pages.pages}">
                <a href="/paper/pages?pageNum=1" class="page-link">首页</a>
                <a href="/paper/pages?pageNum=${pages.prePage}" class="page-link">上一页</a>
            </c:when>
            <c:otherwise>
               <a href="/paper/pages?pageNum=1" class="page-link">首页</a>
               <a href="/paper/pages?pageNum=${pages.prePage}" class="page-link">上一页</a>
               <a href="/paper/pages?pageNum=${pages.nextPage}" class="page-link">下一页</a>
               <a href="/paper/pages?pageNum=${pages.pages}" class="page-link">末页</a>
            </c:otherwise>
        </c:choose>
    </c:if>
    <span class="page-link" style="color: dimgrey">共${pages.total}条</span>
</div>


<!-- 添加模态框 -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title">设置新的考卷</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <%--<form action="${pageContext.request.contextPath}/account/addAccount" method="post">--%>
            <!-- 模态框主体 -->
            <div class="modal-body">

                <div class="form-group">
                    <label for="paperName">试卷标题:</label>
                    <input type="text" class="form-control" id="paperName" name="paperName" placeholder="请输入标题">
                </div>
                <div class="form-group">
                    <label for="testDate">考试类型:</label>
                    &nbsp;&nbsp;&nbsp;
                    <label><input type="radio" value="0" name="paperType" id="r1">日常练习题</label>
                    &nbsp;&nbsp;&nbsp;
                    <label><input type="radio" value="1" name="paperType" id="r2">技能考试题</label>
                </div>
                <div id="skill">
                    <div class="form-group">
                        <label for="testDate">考试时长:</label>
                        <input type="text" class="form-control" id="testDate" name="testDate" placeholder="请输入考试时长">
                    </div>
                    <div class="form-group">
                        <label for="paperNumber">题量:</label>
                        <input type="text" class="form-control" id="paperNumber" name="paperNumber" placeholder="请输入考题数量">
                    </div>
                    <div class="form-group">
                        <label for="cotScore">总分:</label>
                        <input type="text" class="form-control" id="cotScore" name="cotScore" placeholder="请输入考卷总分">
                    </div>
                </div>

            </div>
            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="subpaper()">保存</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
            <%--</form>--%>

        </div>
    </div>
</div>

</div>


</body>
</html>
